﻿using TagLib;

namespace HomeDump.Server.Components.MusicSearch
{
	/// <summary>
	/// Class parsing a music file.
	/// </summary>
	public class MusicFileParser : IMusicFileParser
	{
		/// <summary>
		/// Parses a file into a music file.
		/// </summary>
		public MusicFile Parse(string file)
		{
			using (var musicFile = File.Create(file))
			{
				return new MusicFile(
					musicFile.Tag.Title,
					musicFile.Tag.JoinedAlbumArtists,
					musicFile.Tag.Album,
					musicFile.Properties.Duration,
					file);
			}
		}
	}
}